home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / pt-fvc.h < prev    next >
C/C++ Source or Header  |  1996-10-30  |  6KB  |  253 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_tree_fvc2_h)
  24. #define octave_tree_fvc2_h 1
  25.  
  26. #if defined (__GNUG__)
  27. #pragma interface
  28. #endif
  29.  
  30. class ostream;
  31.  
  32. #include <SLList.h>
  33.  
  34. class symbol_record;
  35. class tree_constant;
  36. class tree_function;
  37.  
  38. class tree_walker;
  39.  
  40. #include "mappers.h"
  41. #include "pt-fvc-base.h"
  42. #include "variables.h"
  43.  
  44. // Symbols from the symbol table.
  45.  
  46. class
  47. tree_identifier : public tree_fvc
  48. {
  49.   friend class tree_index_expression;
  50.  
  51. public:
  52.  
  53.   tree_identifier (int l = -1, int c = -1)
  54.     : tree_fvc (l, c), sym (0), maybe_do_ans_assign (false) { }
  55.  
  56.   tree_identifier (symbol_record *s, int l = -1, int c = -1)
  57.     : tree_fvc (l, c), sym (s), maybe_do_ans_assign (false) { }
  58.  
  59.   ~tree_identifier (void) { }
  60.  
  61.   bool is_identifier (void) const
  62.     { return true; }
  63.  
  64.   string name (void) const;
  65.  
  66.   tree_identifier *define (tree_constant *t);
  67.   tree_identifier *define (tree_function *t);
  68.  
  69.   void document (const string& s);
  70.  
  71.   octave_value assign (const octave_value& t);
  72.   octave_value assign (const octave_value_list& args, const octave_value& t);
  73.  
  74.   bool is_defined (void);
  75.  
  76.   void increment (void);
  77.  
  78.   void decrement (void);
  79.  
  80.   tree_fvc *do_lookup (bool& script_file_executed, bool exec_script = true);
  81.  
  82.   void link_to_global (void);
  83.  
  84.   void mark_as_formal_parameter (void);
  85.  
  86.   void mark_for_possible_ans_assign (void)
  87.     { maybe_do_ans_assign = true; }
  88.  
  89.   octave_value eval (bool print);
  90.  
  91.   octave_value_list eval (bool print, int nargout,
  92.               const octave_value_list& args); 
  93.  
  94.   void eval_undefined_error (void);
  95.  
  96.   void accept (tree_walker& tw);
  97.  
  98.   octave_value value (void) const;
  99.  
  100.   octave_value& reference (void);
  101.  
  102. private:
  103.  
  104.   // The symbol record that this identifier references.
  105.   symbol_record *sym;
  106.  
  107.   // True if we should consider assigning the result of evaluating
  108.   // this identifier to the built-in variable ans.
  109.   bool maybe_do_ans_assign;
  110. };
  111.  
  112. // Indirect references to values (structure references).
  113.  
  114. class
  115. tree_indirect_ref : public tree_fvc
  116. {
  117. public:
  118.  
  119.   tree_indirect_ref (int l = -1, int c = -1)
  120.     : tree_fvc (l, c), id (0), indir (0), nm (),
  121.       preserve_ident (false), preserve_indir (false),
  122.       maybe_do_ans_assign (false) { }
  123.  
  124.   tree_indirect_ref (tree_identifier *i, int l = -1, int c = -1)
  125.     : tree_fvc (l, c), id (i), indir (0), nm (),
  126.       preserve_ident (false), preserve_indir (false),
  127.       maybe_do_ans_assign (false) { }
  128.  
  129.   tree_indirect_ref (tree_indirect_ref *i, const string& n,
  130.              int l = -1, int c = -1)
  131.     : tree_fvc (l, c), id (0), indir (i), nm (n),
  132.       preserve_ident (false), preserve_indir (false),
  133.       maybe_do_ans_assign (false) { }
  134.  
  135.   ~tree_indirect_ref (void);
  136.  
  137.   bool is_indirect_ref (void) const
  138.     { return true; }
  139.  
  140.   bool is_identifier_only (void) const
  141.     { return (id && nm.empty ()); }
  142.  
  143.   tree_identifier *ident (void)
  144.     { return id; }
  145.  
  146.   tree_indirect_ref *indirect (void)
  147.     { return indir; }
  148.  
  149.   void preserve_identifier (void)
  150.     { preserve_ident = true; }
  151.  
  152.   void preserve_indirect (void)
  153.     { preserve_indir = true; }
  154.  
  155.   void mark_for_possible_ans_assign (void)
  156.     {
  157.       maybe_do_ans_assign = true;
  158.  
  159.       if (is_identifier_only ())
  160.     id->mark_for_possible_ans_assign ();
  161.     }
  162.  
  163.   string name (void) const;
  164.  
  165.   octave_value eval (bool print);
  166.  
  167.   octave_value_list eval (bool print, int nargout,
  168.               const octave_value_list& args);
  169.  
  170.   octave_value value (void) const;
  171.   octave_value& reference (void);
  172.  
  173.   string elt_name (void)
  174.     { return nm; }
  175.  
  176.   void accept (tree_walker& tw);
  177.  
  178. private:
  179.  
  180.   // The identifier for this structure reference.  For example, in
  181.   // a.b.c, a is the id.
  182.   tree_identifier *id;
  183.  
  184.   // This element just points to another indirect reference.
  185.   tree_indirect_ref *indir;
  186.  
  187.   // The sub-element name.
  188.   string nm;
  189.  
  190.   // True if we should not delete the identifier.
  191.   bool preserve_ident;
  192.  
  193.   // True if we should not delete the indirect reference.
  194.   bool preserve_indir;
  195.  
  196.   // True if we should consider assigning the result of evaluating
  197.   // this identifier to the built-in variable ans.
  198.   bool maybe_do_ans_assign;
  199. };
  200.  
  201. // Builtin functions.
  202.  
  203. class
  204. tree_builtin : public tree_fvc
  205. {
  206. public:
  207.  
  208.   tree_builtin (const string& nm = string ());
  209.  
  210.   tree_builtin (const builtin_mapper_function& m_fcn,
  211.         const string& nm = string ());
  212.  
  213.   tree_builtin (Octave_builtin_fcn f, const string& nm = string ());
  214.  
  215.   ~tree_builtin (void) { }  // XXX ?? XXX
  216.  
  217. //  int is_builtin (void) const;
  218.  
  219.   bool is_mapper_function (void) const
  220.     { return is_mapper; }
  221.  
  222.   octave_value eval (bool print);
  223.  
  224.   octave_value_list eval (bool print, int nargout, const octave_value_list& args);
  225.  
  226.   string name (void) const
  227.     { return my_name; }
  228.  
  229.   void accept (tree_walker& tw);
  230.  
  231. private:
  232.  
  233.   // True if this is a mapper function.
  234.   bool is_mapper;
  235.  
  236.   // A structure describing the mapper function.
  237.   builtin_mapper_function mapper_fcn;
  238.  
  239.   // The actual function, if it is not a mapper.
  240.   Octave_builtin_fcn fcn;
  241.  
  242.   // The name of this function.
  243.   string my_name;
  244. };
  245.  
  246. #endif
  247.  
  248. /*
  249. ;;; Local Variables: ***
  250. ;;; mode: C++ ***
  251. ;;; End: ***
  252. */
  253.